package Demo1;

import java.util.*;

public class demo2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        in.nextLine();

        List<Integer> list = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            String[] temp = in.nextLine().split(" ");
            for (String str : temp) {
                list.add(Integer.parseInt(str));
            }
        }

        Collections.sort(list);

        int m = -1, n = -1;

        for (int i = 1; i < list.size(); i++) {
            int prev = list.get(i - 1);
            int curr = list.get(i);

            if (prev + 2 == curr) {
                m = prev + 1;
            }
            if (prev == curr) {
                n = prev;
            }
            if (m != -1 && n != -1) break;
        }

        System.out.println(m + " " + n);
    }
}

